package com.demo.java.spring.ioc;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextHolder implements ApplicationContextAware {
    private static ApplicationContext ac = null;
    public static ApplicationContext getApplicationContext() {
        return ac;
    }
    public static <T> T getBean(Class<T> clazz) {
        return ac.getBean(clazz);
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextHolder.ac = applicationContext;
    }
}
